/**
	The Minerva Project, DAG Scheduling Tools
	Copyright (C) 2006 Florin Pop & Stefan Bucur

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 */
package ro.pub.cs.minerva.graph;

import java.util.*;

/**
 * @author Stefan Bucur
 *
 */
public class GraphNode implements Cloneable{
	
	/*
	 * PACKAGE ACCESS LEVEL MEMBERS
	 */
	
	Graph graph;
	HashMap<GraphNode, GraphLink<? extends GraphNode>> outLinks;
	HashMap<GraphNode, GraphLink<? extends GraphNode>> inLinks;
	
	int startTime = 0;
	int endTime = 0;
	int crColor = GraphSearchInfo.COLOR_WHITE;
	GraphNode parent = null;
	
    
    /*
     * PUBLIC METHODS
     */
    
    /**
     * The default constructor
     */
	
	public GraphNode() {
		graph = null;
		
		outLinks = new HashMap<GraphNode, GraphLink<? extends GraphNode>>();
		inLinks = new HashMap<GraphNode, GraphLink<? extends GraphNode>>();
	}
	
	public int hashCode() {
		return super.hashCode();
	}
	
	public Object clone() throws CloneNotSupportedException {
		GraphNode result = (GraphNode)super.clone();
		
		result.outLinks = new HashMap<GraphNode, GraphLink<? extends GraphNode>>();
		result.inLinks = new HashMap<GraphNode, GraphLink<? extends GraphNode>>();
		
		graph = null;
		
		return result;
	}

	/**
	 * 
	 * @return the Graph object that owns the node, or null if the node
	 * has not been added to a graph.
	 */
	public Graph getGraph() {
		return graph;
	}
	
	/**
	 * 
	 * @return 
	 */
	public Iterator<GraphLink<? extends GraphNode>> getOutLinksIterator() {
		return outLinks.values().iterator();
	}
	
	/**
	 * 
	 */
	public Iterator<GraphLink<? extends GraphNode>> getInLinksIterator() {
		return inLinks.values().iterator();
	}
	
	/**
	 * 
	 * @return
	 */
	public int getOutLinksCount() {
		return outLinks.size();
	}
	
	/**
	 * 
	 * @return
	 */
	public int getInLinksCount() {
		return inLinks.size();
	}
	
	/**
	 * 
	 * @param node
	 * @return
	 */
	public boolean hasNextNode(GraphNode node) {
		return outLinks.containsKey(node);
	}
}
